package com.pingan.service.impl;

import com.pingan.annotation.RequiredLog;
import com.pingan.mapper.NoticeMapper;
import com.pingan.enums.NoticeTypeEnum;
import com.pingan.pojo.NoticeType;
import com.pingan.pojo.Notices;
import com.pingan.service.NoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class NoticeServiceImpl implements NoticeService {
    @Autowired
    private NoticeMapper noticeMapper;

    @RequiredLog(operation = "公告查询")
    @Override
    public List<Notices> getNoticeList(Notices req) {
        List<Notices> noticeList = noticeMapper.getNoticeList(req);
        for (int i = 1; i <= noticeList.size(); i++) {
            noticeList.get(i-1).setSort(i);
        }
        return noticeList;
    }

    @Override
    public Integer doAddNotice(Notices req) {
        return noticeMapper.doAddNotice(req);
    }

    @Override
    public Integer doDelNotice(Integer[] ids) {
        return noticeMapper.doDelNotice(ids);
    }

    @Override
    public Integer doUpdateNotice(Notices req) {
        return noticeMapper.doUpdateNotice(req);
    }

    @Override
    public List<NoticeType> getNoticeType() {
        List<NoticeType> list = new ArrayList<>();
        for (NoticeTypeEnum value : NoticeTypeEnum.values()) {
            NoticeType type = new NoticeType();
            type.setCode(value.getCode());
            type.setName(value.getName());
            list.add(type);
        }
        return list;
    }
}
